﻿using System;
using System.Collections.Generic;
using Driven.ProcessScheduler.Interfaces;
using NUnit.Framework;
using Rhino.Mocks;

namespace Driven.ProcessScheduler.Test
{
    [TestFixture]
    public class ScheduleManagerTest
    {
        [Test]
        public void AbleToAddSchedule()
        {
            var schedule = new Schedule(string.Empty, null, TimeSpan.Zero, 0);
            var manager = new ScheduleManager(new List<ISchedule> { schedule });

            Assert.AreSame(schedule, manager.Schedules[0]);
        }

        [Test]
        public void AbleToMultipleSchedules()
        {
            var schedule1 = new Schedule(string.Empty, null, TimeSpan.Zero, 0);
            var schedule2 = new Schedule(string.Empty, null, TimeSpan.Zero, 0);
            var manager = new ScheduleManager(new List<ISchedule> { schedule1, schedule2 });

            Assert.AreEqual(manager.Schedules.Count, 2);
        }

        [Test]
        public void ScheduleIsExecuted()
        {
            var component = MockRepository.GenerateStub<IScheduledComponent>();
            var schedule = MockRepository.GenerateMock<Schedule>(string.Empty, component, TimeSpan.Zero, 0);
            const string executed = "1 executed";

            schedule
                .Expect(x => x.Execute())
                .Return(new[] { executed })
                .Repeat.Once();

            var scheduleManager = new ScheduleManager(new List<ISchedule> { schedule });
            List<string> result = scheduleManager.Execute();

            Assert.That(result[0].Contains(executed));
            schedule.VerifyAllExpectations();
        }
        
    }
}